package scheduler;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

import pool.bean.Property_details_Bean;

import utility.MessageGenerator;
import utility.PeriodDate;
import User.Uservalidation;
import control.Control;
import control.RequestParameter;

import dbmanager.DBManager;
import dbmanager.GetIdName;

public class UpdateSchedule
{
	DBManager database;
	Hashtable<Object, Object> scheduletable =new Hashtable<Object, Object>();
	String startdate="startdate";
	String enddate="enddate";
	String currentdate = "currentdate";
	String pattern  = "yyyy-MM-dd";
	String period = "period";
	String DAY="day";
	GetIdName gid;
	String object;
	String USERNAME="+911234567891";
	
	public void setData(DBManager database,Hashtable<Object, Object> schedule,String object)
    {
    	this.database = database;
    	this.scheduletable.putAll(schedule);
    	this.gid = new GetIdName(database);
    	this.object =object;
    }
    
    public boolean getResult()
    {	
		try
		{	
			PeriodDate perioddate= new PeriodDate(database);
			SimpleDateFormat sdm = new SimpleDateFormat(this.pattern);
			String date = sdm.format(new Date());
			Date d = sdm.parse(date);
			date = sdm.format(d);
			period = gid.getId(scheduletable.get(period).toString());
			if(scheduletable.containsKey(startdate))
			{
				startdate =  scheduletable.get(startdate).toString();
				currentdate =scheduletable.get(currentdate).toString();
				int i = perioddate.compareDate(currentdate, currentdate);
				if(i==1)
				{		
					return false;
				}	
			}
			if(scheduletable.containsKey(enddate))
			{
				enddate =  scheduletable.get(enddate).toString();
				int i = perioddate.compareDate(enddate, date);
				if(i<0)
				{
					return false;
				}	
			}
			if(scheduletable.containsKey(currentdate))
			{
				currentdate =scheduletable.get(currentdate).toString();				
				int i=perioddate.compareDate(currentdate, date);
				if(i==0)
				{
					if(scheduletable.containsKey(period))
					{
						String nextdate= perioddate.getNextDate(period,startdate);
						
					}
					return true;
				}
			}
		} catch (Exception e) 
		{	
			e.printStackTrace();
			return false;
		}
		return true;
    }
}
